let videoAd = null
var t = getApp(), a = null;
// 在页面中定义插屏广告
let interstitialAd = null

Page({
    data: {
        ad: {},
        isTiptrue: !0,
        test:0,
        jiliShow:false,
        tuijian:[],
        isLoading:true,
        bannerList:[],
        yuliu:[],
        bannerAd:{},
        koutu:'',
        kouzhao:'',
        tuijianShow:true
    },
    elm(e){
      let {appid,path}= e.currentTarget.dataset.object
      wx.navigateToMiniProgram({
        appId: appid,
        path
      })
    },
    mt(){
      wx.navigateToMiniProgram({
        appId: 'wx2c348cf579062e56',
        path:'/outer_packages/r2xinvite/coupon/coupon?inviteCode=NnOIp-QOs8SiYF1dcSlL5r8phPrCf6qkH7evMyjIoup2NXxNCLYcBbd3bqpv2X2IkuG3bVsghPgyD0Chu_9UVKFyUGZ0sZVlim4c5sEAkhltbW727Oj2m0g2zCLAA_nLVggYaDpH4c5q69fGxI9zFEqvk4lPn2CgMMrGmys7eIo'
      })
    },
    xiaoshuo(){
      wx.navigateToMiniProgram({
        appId: 'wx6820760b1be48361'
      })
    },
    jili(){
      let that = this
      console.log(videoAd)
      if (videoAd) {
        videoAd.show()
          .then(() => {
            that.resetTime()
          })
          .catch(() => {
            // 失败重试
            videoAd.load()
              .then(() => videoAd.show().then(() => {
                that.resetTime()
              }))
              .catch(err => {
                console.log('激励视频 广告显示失败')
              })
          })
      }
    },
    test(){
        t.globalData.test == 1&&wx.navigateTo({
          url: '/pages/test/test',
        })
    },
    load(e){
        console.log(e)
    },
    error(e){
        console.log(e)
    },
    onShow(){
        
    },
    onLoad: function() {
        var e = this;
        let that = this
        let t = getApp()
        wx.request({
          url: getApp().globalData.requestUrl+'/xiaochengxu/getAppTuijian',
          success(res){
            console.log(res,'推荐')
            that.setData({
              bannerList:res.data.results
            })
            
              that.setData({
                isLoading:false
              })
          } 
        })
        
          wx.request({
            url: getApp().globalData.requestUrl+'/xiaochengxu/getAppAd',
            success(res){
              console.log(res)
              if(res.data.code == 200){
                t.globalData.tuijiantype =res.data.results[0].tuijiantype
                // if(res.data.results[0].tuijiantype == 1 || res.data.results[0].tuijiantype == null){
                //   that.setData({
                //     tuijianShow:true
                //   })
                // }
                t.globalData.selfAd = [{
                  "id": res.data.results[0].banner,
                  "type": "banner"
                }, {
                  "id": res.data.results[0].video,
                  "type": "video"
                }]
                t.globalData.adTest = [{
                  "id": res.data.results[0].chaping,
                  "type": "chaping"
                }]
                t.globalData.gezi = res.data.results[0].gezi
                getApp().chaping(true)
                that.setData({
                    ad: getApp().globalData.selfAd.filter(item=>item.type == 'video')[0],
                    bannerAd:getApp().globalData.selfAd.filter(item=>item.type == 'banner')[0]
                });
                console.log(that.data.ad)
                var i = wx.getStorageSync("loadOpen");
                void 0 == i || "" == i ? that.setData({
                    isTiptrue: !0
                }) : that.setData({
                    isTiptrue: !1
                });
                that.setData({
                  tuijian:getApp().globalData.tuijian
                })
              }
            }
          })
          
              
    },
    onShareTimeline(){
        return {title:'史上最好用的修图，表情制作，图片制作工具'}
    },
    tuijianLink(e){
      let {id}= e.currentTarget.dataset
      wx.navigateToMiniProgram({
        appId: id,
      })
    },
    onShareAppMessage: function() {
        return {
            title: "超好用的图片编辑小程序",
            path: "pages/index/index",
            imageUrl: "/image/maskshareimg.jpg"
        };
    },
    moreLink(){
      wx.navigateTo({
        url: '/pages/more/more',
      })
    },
    closeGuide: function(t) {
        wx.setStorage({
            key: "loadOpen",
            data: "OpenTwo"
        }), this.setData({
            isTiptrue: !1
        });
    }
});